package HuffmanTree;

public class Node<T> implements Comparable<Node<T>> {
	public T data; // 数据域
	public Node<T> left; // 左孩子域
	public Node<T> right; // 右孩子域
	public Node<T> parent; // 双亲域
	public int weight; // 权值

	public Node(T data, int weight) {
		this.data = data;
		this.weight = weight;
		left = null;
		right = null;
	}

	@Override
	public int compareTo(Node<T> node) {
		if (node.weight > this.weight) {
			return 1;
		} else if (node.weight < this.weight) {
			return -1;
		}
		return 0;
	}

	@Override
	public String toString() {
		return "[data:" + this.data + ", weight:" + this.weight + "]";
	}

	// 比较两个结点值是否相等，覆盖Object类的equals(obj)方法
	public boolean equals(Object obj) {
		return obj == this || obj instanceof Node && this.data.equals(((Node<T>) obj).data);
	}
}
